package listview.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ExpandableListView;

import java.util.ArrayList;
import java.util.List;

import entity.Chid;
import listview.adapter.MyHeadAdapter;
import utils.ToastUtils;
import view.lyd.com.sectionrecyclerviewdemo.R;


/**
 * http://blog.csdn.net/chenliguan/article/details/48183917
 * <p>
 * 2）布局
 * Android：divider 边框线条 = “#FFFFFF”/ “@drawable/list”
 * android：dividerHeight 边框线条
 * <p>
 * 3）去除分割线
 * ①设置android:divider=”@null”
 * ②android:divider=”#00000000” #00000000后面两个零表示透明
 * ③.setDividerHeight(0) 高度设为0
 * <p>
 * 4）去除滚动棒
 * android:scrollbars=”none”
 *
 *
 * 折叠的ListView
 */
public class TestAddHeadActivity extends AppCompatActivity {

    private ExpandableListView listView;


    // 准备数据
    private List<entity.Group> list_data;
    private ExpandableListView mExpandList;

    private int[] images = {R.mipmap.icon, R.mipmap.ic_launcher, R.mipmap.icon};


    String[] armTypes = new String[]{"神族", "虫族", "人族"};
    String[][] arms = new String[][]{
            {"狂战士", "龙骑士", "黑暗圣堂"},
            {"小狗", "飞龙", "自爆妃子"},
            {"步兵", "伞兵", "护士mm"}
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_test_add_head);

        initView();
        addData();
        bindAdapter();

        initListener();
    }

    private void initListener() {
        //TODO   第一个参数为父item   第二个i1 为子item
        listView.setSelectedGroup(0);
        listView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
            @Override
            public boolean onChildClick(ExpandableListView expandableListView, View view, int i, int i1, long l) {

                ToastUtils.showToast(getApplicationContext(),"子Item点击了" + i );
                return false;
            }
        });
        listView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
            @Override
            public boolean onGroupClick(ExpandableListView expandableListView, View view, int i, long l) {
                ToastUtils.showToast(getApplicationContext(),"点击了Head" + i );
                return false;
            }
        });
    }

    private void initView() {

        listView = (ExpandableListView) findViewById(R.id.list_view);


    }

    private void addData() {
        list_data = new ArrayList<entity.Group>();
        for (int i = 0; i < 5; i++) {
            entity.Group group = new entity.Group();
            group.setTxt("组" + (i));


            List<Chid> child = new ArrayList<Chid>();
            for (int j = 0; j < 3; j++) {
                Chid chid = new Chid();
                chid.setTxt("子" + (j));
                child.add(chid);
            }
            group.getList_child().addAll(child);
            list_data.add(group);
        }
    }


    private void bindAdapter() {


//        MyHeadAdapter myHeadAdapter = new MyHeadAdapter(armTypes, arms, getApplicationContext());
        MyHeadAdapter myHeadAdapter = new MyHeadAdapter(getApplicationContext(), list_data);
        listView.setAdapter(myHeadAdapter);

        if (listView.getHeaderViewsCount() == 0) {
            listView.addHeaderView(getLayoutInflater().inflate(R.layout.header,
                    listView, false));

        }
//        myHeadAdapter.notifyDataSetChanged();
    }


}
